home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / t-adainc / s-tasclo.adb < prev    next >
Text File  |  1994-05-19  |  5KB  |  172 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                     S Y S T E M . T A S K _ C L O C K                    --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.8 $                             --
  10. --                                                                          --
  11. --           Copyright (c) 1991,1992,1993, FSU, All Rights Reserved         --
  12. --                                                                          --
  13. --  GNARL is free software; you can redistribute it and/or modify it  under --
  14. --  terms  of  the  GNU  Library General Public License as published by the --
  15. --  Free Software Foundation; either version 2,  or (at  your  option)  any --
  16. --  later  version.   GNARL is distributed in the hope that it will be use- --
  17. --  ful, but but WITHOUT ANY WARRANTY; without even the implied warranty of --
  18. --  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. --  eral Library Public License for more details.  You should have received --
  20. --  a  copy of the GNU Library General Public License along with GNARL; see --
  21. --  file COPYING. If not, write to the Free Software Foundation,  675  Mass --
  22. --  Ave, Cambridge, MA 02139, USA.                                          --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Std; use System.Std;
  27.  
  28. package body System.Task_Clock is
  29.  
  30.    -----------------------
  31.    -- Stimespec_Seconds --
  32.    -----------------------
  33.  
  34.    function Stimespec_Seconds (TV : Stimespec) return Integer is
  35.    begin
  36.       return Integer (TV.Val / Stimespec_Sec_Unit.Val);
  37.    end Stimespec_Seconds;
  38.  
  39.    ------------------------
  40.    -- Stimespec_Nseconds --
  41.    -------------------------
  42.  
  43.    function Stimespec_NSeconds (TV : Stimespec) return Integer is
  44.    begin
  45.       return
  46.         Integer (TV.Val - Time_Base (Stimespec_Seconds (TV)) *
  47.           Stimespec_Sec_Unit.Val);
  48.    end Stimespec_NSeconds;
  49.  
  50.    -------------
  51.    -- Time_Of --
  52.    -------------
  53.  
  54.    function Time_Of (S, NS : Integer) return Stimespec is
  55.    begin
  56.       return Stimespec' (Val => Stimespec_Sec_Unit.Val * Time_Base (S) +
  57.         Time_Base (NS));
  58.    end Time_Of;
  59.  
  60.    ---------------------------
  61.    -- Stimespec_To_Duration --
  62.    ---------------------------
  63.  
  64.    function Stimespec_To_Duration (TV : Stimespec) return Duration is
  65.    begin
  66.       return Duration (float (TV.Val) / 10#1.0#E9);
  67.    end Stimespec_To_Duration;
  68.  
  69.    ---------------------------
  70.    -- Duration_To_Stimespec --
  71.    ---------------------------
  72.  
  73.    function Duration_To_Stimespec (Time : Duration) return Stimespec is
  74.    begin
  75.       return Stimespec' (Val => Time_Base (Time * 10#1#E9));
  76.    end Duration_To_Stimespec;
  77.  
  78.    ---------
  79.    -- "-" --
  80.    ---------
  81.  
  82.    --  Unary minus
  83.    function "-" (TV : Stimespec) return Stimespec is
  84.    begin
  85.       return Stimespec' (Val => -TV.Val);
  86.    end "-";
  87.  
  88.    -------------
  89.    -- LL_Plus --
  90.    -------------
  91.  
  92.    function "+" (LTV, RTV : Stimespec) return Stimespec is
  93.    begin
  94.       return Stimespec' (Val => LTV.Val + RTV.Val);
  95.    end "+";
  96.  
  97.    --------------
  98.    -- LL_Minus --
  99.    --------------
  100.  
  101.    function "-" (LTV, RTV : Stimespec) return Stimespec is
  102.    begin
  103.       return Stimespec' (Val => LTV.Val - RTV.Val);
  104.    end "-";
  105.  
  106.    -----------------
  107.    -- LL_Multiply --
  108.    -----------------
  109.  
  110.    function "*" (TV : Stimespec; N : Integer) return Stimespec is
  111.    begin
  112.       return Stimespec' (Val => TV.Val * Time_Base (N));
  113.    end "*";
  114.  
  115.    -------------------
  116.    -- LL_Int_Divide --
  117.    -------------------
  118.  
  119.    --  Integer division of Stimespec
  120.  
  121.    function "/" (TV : Stimespec; N : Integer) return Stimespec is
  122.    begin
  123.       return Stimespec' (Val => TV.Val / Time_Base (N));
  124.    end "/";
  125.  
  126.    ---------------
  127.    -- LL_Divide --
  128.    ---------------
  129.  
  130.    function "/" (LTV, RTV : Stimespec) return Stimespec is
  131.    begin
  132.       return Time_Of (0, Integer (LTV.Val / RTV.Val));
  133.    end "/";
  134.  
  135.    ---------
  136.    -- "<" --
  137.    ---------
  138.  
  139.    function "<" (LTV, RTV : Stimespec) return Boolean is
  140.    begin
  141.       return LTV.Val < RTV.Val;
  142.    end "<";
  143.  
  144.    ----------
  145.    -- "<=" --
  146.    ----------
  147.  
  148.    function "<=" (LTV, RTV : Stimespec) return Boolean is
  149.    begin
  150.       return LTV.Val < RTV.Val or else RTV.Val = LTV.Val;
  151.    end "<=";
  152.  
  153.    ---------
  154.    -- ">" --
  155.    ---------
  156.  
  157.    function ">" (LTV, RTV : Stimespec) return Boolean is
  158.    begin
  159.       return RTV.Val < LTV.Val;
  160.    end ">";
  161.  
  162.    ----------
  163.    -- ">=" --
  164.    ----------
  165.  
  166.    function ">=" (LTV, RTV : Stimespec) return Boolean is
  167.    begin
  168.       return LTV.Val > RTV.Val or LTV.Val = RTV.Val;
  169.    end ">=";
  170.  
  171. end System.Task_Clock;
  172.